#include "tetrixwindow.h"
#include"tetrixboard.h"
#include<QLabel>
#include<QLCDNumber>
#include<QPushButton>
#include<QApplication>
#include<QVBoxLayout>
#include<QHBoxLayout>

TetrixWindow::TetrixWindow(QWidget *parent)
    : QWidget(parent),
    board(new TetrixBoard)
{
    this->next_piece_label=new QLabel;
    this->next_piece_label->setFrameStyle(QFrame::Box|QFrame::Raised);
    this->next_piece_label->setAlignment(Qt::AlignCenter);
    board->setNextPieceLabe(this->next_piece_label);

    this->score_lcd=new QLCDNumber(5);
    this->score_lcd->setSegmentStyle(QLCDNumber::Filled);

    this->start_pushButton=new QPushButton("start");
    this->start_pushButton->setFocusPolicy(Qt::NoFocus);

    this->quit_pushButton=new QPushButton("quit");
    this->quit_pushButton->setFocusPolicy(Qt::NoFocus);

    this->pause_goon_pushButton=new QPushButton("pause");
    this->pause_goon_pushButton->setFocusPolicy(Qt::NoFocus);

    connect(this->start_pushButton,&QPushButton::clicked,this->board,&TetrixBoard::start);
    connect(this->quit_pushButton,&QPushButton::clicked,qApp,&QApplication::quit);
    connect(this->pause_goon_pushButton,&QPushButton::clicked,this->board,&TetrixBoard::pause);
    connect(this->board,&TetrixBoard::scoreChanged,this->score_lcd,qOverload<int>(&QLCDNumber::display));


    QVBoxLayout* vLayout=new QVBoxLayout;
    QLabel* next=new QLabel("NEXT",this);
    vLayout->addWidget(next);
    vLayout->addWidget(this->next_piece_label);
    vLayout->addWidget(this->start_pushButton);
    vLayout->addWidget(this->pause_goon_pushButton);

    vLayout->addSpacing(50);

    QLabel* label=new QLabel("SCORE",this);
    vLayout->addWidget(label);
    vLayout->addWidget(this->score_lcd);
    vLayout->addWidget(this->quit_pushButton);

    QHBoxLayout* hLayout=new QHBoxLayout(this);
    hLayout->addWidget(this->board);
    hLayout->addLayout(vLayout);


    setWindowTitle("Tetrix");

    resize(630,500);

}

TetrixWindow::~TetrixWindow() {}
